package test;

import test.LIfeService.LIFeService;

import java.awt.Component;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;

public class Menu extends JFrame {
    public Menu(String loggedInUsername) {
        this.setTitle("智慧社区菜单");
        this.setSize(600, 400);
        this.setDefaultCloseOperation(3);
        this.setLocationRelativeTo((Component)null);
        JPanel mainPanel = new JPanel(new GridLayout(3, 1, 10, 10));
        mainPanel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
        JButton communityManagementButton = new JButton("社区管理与政务服务");
        JButton lifeServiceButton = new JButton("生活服务与便民功能");
        JButton socialCultureButton = new JButton("社交与社区文化");
        Font buttonFont = new Font("SimSun", 1, 16);
        communityManagementButton.setFont(buttonFont);
        lifeServiceButton.setFont(buttonFont);
        socialCultureButton.setFont(buttonFont);
        communityManagementButton.addActionListener((e) -> {
            MannageService.main((String[])null);
            this.dispose();
        });
        lifeServiceButton.addActionListener((e) -> {
            (new LIFeService()).show();
            this.dispose();
        });
        socialCultureButton.addActionListener((e) -> {
            JFrame cultureFrame = new JFrame("社交与社区文化");
            cultureFrame.setSize(600, 400);
            cultureFrame.setLocationRelativeTo((Component)null);
            JPanel panel = new JPanel(new GridLayout(3, 1, 10, 10));
            panel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
            JButton forumBtn = new JButton("社区论坛");
            JButton activityBtn = new JButton("线上活动");
            JButton volunteerBtn = new JButton("志愿者服务");
            Font btnFont = new Font("SimSun", 1, 16);
            forumBtn.setFont(btnFont);
            activityBtn.setFont(btnFont);
            volunteerBtn.setFont(btnFont);
            forumBtn.addActionListener((ev) -> {
                (new CommunityForum()).show();
                cultureFrame.dispose();
            });
            activityBtn.addActionListener((ev) -> {
                (new OnlineActivity()).show();
                cultureFrame.dispose();
            });
            volunteerBtn.addActionListener((ev) -> {
                (new VolunteerService()).show();
                cultureFrame.dispose();
            });
            JButton backBtn = new JButton("返回主菜单");
            backBtn.addActionListener((ev) -> {
                cultureFrame.dispose();
                this.setVisible(true);
            });
            panel.add(forumBtn);
            panel.add(activityBtn);
            panel.add(volunteerBtn);
            JPanel bottomPanel = new JPanel(new FlowLayout(2));
            bottomPanel.add(backBtn);
            cultureFrame.add(panel, "Center");
            cultureFrame.add(bottomPanel, "South");
            this.setVisible(false);
            cultureFrame.setVisible(true);
        });
        mainPanel.add(communityManagementButton);
        mainPanel.add(lifeServiceButton);
        mainPanel.add(socialCultureButton);
        this.add(mainPanel, "Center");
        this.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent windowEvent) {
                System.exit(0);
            }
        });
    }

    public static void main(String[] args) {
        SwingUtilities.invokeLater(() -> {
            String loggedInUsername = null;
            Menu menu = new Menu(loggedInUsername);
            menu.setVisible(true);
        });
    }
}
